<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">机会编号</label>
        <el-input v-model="query.chcId" clearable placeholder="机会编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">机会来源</label>
        <el-input v-model="query.chcSource" clearable placeholder="机会来源" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">客户名称</label>
        <el-input v-model="query.chcCustName" clearable placeholder="客户名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">成功率</label>
        <el-input v-model="query.chcRate" clearable placeholder="成功率" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">联系人</label>
        <el-input v-model="query.chcLinkman" clearable placeholder="联系人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">联系电话</label>
        <el-input v-model="query.chcTel" clearable placeholder="联系电话" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">创建机会编号</label>
        <el-input v-model="query.chcCreateId" clearable placeholder="创建机会编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">机会创建人</label>
        <el-input v-model="query.chcCreateBy" clearable placeholder="机会创建人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">创建时间</label>
        <el-input v-model="query.chcCreateDate" clearable placeholder="创建时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">机会处理编号</label>
        <el-input v-model="query.chcDueId" clearable placeholder="机会处理编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">处理人</label>
        <el-input v-model="query.chcDueTo" clearable placeholder="处理人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">处理时间</label>
        <el-input v-model="query.chcDueDate" clearable placeholder="处理时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">处理状态</label>
        <el-input v-model="query.chcStatus" clearable placeholder="处理状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="机会来源">
            <el-input v-model="form.chcSource" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户名称" prop="chcCustName">
            <el-input v-model="form.chcCustName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="机会概要" prop="chcTitle">
            <el-input v-model="form.chcTitle" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="成功率" prop="chcRate">
            <el-input v-model="form.chcRate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="联系人">
            <el-input v-model="form.chcLinkman" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input v-model="form.chcTel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="机会描述" prop="chcDesc">
            <el-input v-model="form.chcDesc" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="机会创建人" prop="chcCreateBy">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="创建时间" prop="chcCreateDate">
            <el-date-picker v-model="form.chcCreateDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="机会处理编号">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="处理人">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="处理时间">
            <el-date-picker v-model="form.chcDueDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="处理状态" prop="chcStatus">
            未设置字典，请手动设置 Select
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="chcId" label="机会编号" />
        <el-table-column prop="chcSource" label="机会来源" />
        <el-table-column prop="chcCustName" label="客户名称" />
        <el-table-column prop="chcTitle" label="机会概要" />
        <el-table-column prop="chcRate" label="成功率" />
        <el-table-column prop="chcLinkman" label="联系人" />
        <el-table-column prop="chcTel" label="联系电话" />
        <el-table-column prop="chcDesc" label="机会描述" />
        <el-table-column prop="chcCreateId" label="创建机会编号" />
        <el-table-column prop="chcCreateBy" label="机会创建人" />
        <el-table-column prop="chcCreateDate" label="创建时间" />
        <el-table-column prop="chcDueId" label="机会处理编号" />
        <el-table-column prop="chcDueTo" label="处理人" />
        <el-table-column prop="chcDueDate" label="处理时间" />
        <el-table-column prop="chcStatus" label="处理状态" />
        <el-table-column v-if="checkPer(['admin','salChance:edit','salChance:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSalChance from '@/api/salChance'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { chcId: null, chcSource: null, chcCustName: null, chcTitle: null, chcRate: null, chcLinkman: null, chcTel: null, chcDesc: null, chcCreateId: null, chcCreateBy: null, chcCreateDate: null, chcDueId: null, chcDueTo: null, chcDueDate: null, chcStatus: null }
export default {
  name: 'SalChance',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '客户管理', url: 'api/salChance', idField: 'chcId', sort: 'chcId,desc', crudMethod: { ...crudSalChance }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'salChance:add'],
        edit: ['admin', 'salChance:edit'],
        del: ['admin', 'salChance:del']
      },
      rules: {
        chcCustName: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        chcTitle: [
          { required: true, message: '机会概要不能为空', trigger: 'blur' }
        ],
        chcRate: [
          { required: true, message: '成功率不能为空', trigger: 'blur' }
        ],
        chcDesc: [
          { required: true, message: '机会描述不能为空', trigger: 'blur' }
        ],
        chcCreateId: [
          { required: true, message: '创建机会编号不能为空', trigger: 'blur' }
        ],
        chcCreateBy: [
          { required: true, message: '机会创建人不能为空', trigger: 'blur' }
        ],
        chcCreateDate: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        chcStatus: [
          { required: true, message: '处理状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'chcId', display_name: '机会编号' },
        { key: 'chcSource', display_name: '机会来源' },
        { key: 'chcCustName', display_name: '客户名称' },
        { key: 'chcRate', display_name: '成功率' },
        { key: 'chcLinkman', display_name: '联系人' },
        { key: 'chcTel', display_name: '联系电话' },
        { key: 'chcCreateId', display_name: '创建机会编号' },
        { key: 'chcCreateBy', display_name: '机会创建人' },
        { key: 'chcCreateDate', display_name: '创建时间' },
        { key: 'chcDueId', display_name: '机会处理编号' },
        { key: 'chcDueTo', display_name: '处理人' },
        { key: 'chcDueDate', display_name: '处理时间' },
        { key: 'chcStatus', display_name: '处理状态' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
